import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_myshop/model/shoping_car.dart';
import 'common_method.dart';
import 'package:flutter_myshop/config/serivce_url.dart';

//cate get
// 获得首页内容数据
Future getHomePageContent() {
  print('开始获取首页数据...............');
  return get(getServicePath['homePageContent']);
}

// 获得首页内容数据,可以带参数page
Future getHomePageBelowContent({page: 0}) {
  print('开始获取首页下拉商品数据...............');

  // '?' 后面的数据
  Map<String, dynamic> queryParameters = {"page": page};

  return get(getServicePath['homePageBelowContent'],
      queryParameters: queryParameters);
}

// 获得分类页面的分类数据
Future getCategory() {
  print('开始获取分类数据...............');
  return get(getServicePath['category']);
}

// 获得分类页面的商品数据
// 小分类Id可以不填,默认为所有
Future getCategoryPageContent(
    {@required String bigCategoryId,
    String smallCategoryId = "0",
    @required int page}) async {
  print('开始获取分类商品...............');

  // '?' 后面的数据
  Map<String, dynamic> queryParameters = {
    "page": page,
    "bigCategoryId": bigCategoryId,
    "smallCategoryId": smallCategoryId
  };
  return get(getServicePath['categoryPageContent'],
      queryParameters: queryParameters);
}

/// 获得商品详情数据
// id是必备的参数
Future getGoodDetail({@required String id}) async {
  print('开始获取商品详情...............');

  // '?' 后面的数据
  Map<String, dynamic> queryParameters = {
    "id": id,
  };
  return get(getServicePath['goodDetail'], queryParameters: queryParameters);
}

/// 得到购物车内容
Future getShopingCar() async {
  print('开始获取购物车内容...............');
  return get(getServicePath['shopingCar']);
}

/// 得到购物车内容
Future getUserSimpleInfo() async {
  print('开始获取用户基本信息...............');
  return get(getServicePath['userSimpleInfo']);
}

//cate post
Future updateShopingCar({@required List<Good> goodList}) async {
  print(' 开始更新购物车...............');
  return post(postServicePath['updateShopingCar'],
      formData: json.encode(goodList).toString());
}
